import QtQuick 2.0
import QtQuick.Controls 1.2

// 简易网络图片浏览器
Rectangle {
    width: 480;
    height: 320;
    color: "#121212";

    // 打转loading组件
    BusyIndicator {
        id: busy;
        running: true;
        anchors.centerIn: parent;
        z: 2;
    }

    // 用于加载错误时显示错误信息
    Label {
        id: stateLabel;
        visible: false;
        anchors.centerIn: parent;
        z: 3;
    }

    Image {
        id: imageViewer;
        asynchronous: true;
        cache: false;
        anchors.fill: parent;
        fillMode: Image.PreserveAspectFit; // 图片去适应框框,比例不变
        onStatusChanged: {
            // 加载时打转
            if (imageViewer.status === Image.Loading) {
                busy.running = true;
                stateLabel.visible = false;
            }
            // 加载完不转
            else if(imageViewer.status === Image.Ready){
                busy.running = false;
            }
            // 加载错不转并显示error提示
            else if(imageViewer.status === Image.Error){
                busy.running = false;
                stateLabel.visible = true;
                stateLabel.text = "ERROR";
            }
        }
    }
    Component.onCompleted: {
        imageViewer.source = "http://imgsrc.baidu.com/forum/pic/item/10830dd9f2d3572cc2f916548713632763d0c3f6.jpg";
    }

}
